import ajax from './index'

export interface GetCustomerParam {
  pagination: {
    currentPage: number,
    limit?: number
  },
  name?: string,
  phone?: string,
  address?: string,
}

export interface Customer {
  id: number,
  name: string,
  amount: number,
  phone: string,
  distribution: number,
  products_name: string,
  product_coding: string,
  shipped_number: number,
  address: string,
  address_obj: string,
  detailed_address: string,
  start_time: string,
  end_time: string,
  pause_recording: string,
  milkman_id: number | string,
}

export interface CustomerOptionParam {
  id?: number,
  name: string,
  amount: number,
  phone: string,
  distribution: number | string,
  products_name: string,
  product_coding: string,
  address: string,
  address_obj: string,
  detailed_address: string,
  shipped_number?: number,
  start_time: string,
  end_time?: string,
  pause_recording?: string,
  milkman_id: number | string,
}
export interface Pagnate {
  data: Customer[],
  pagination: {
    currentPage: number
    total: number
    totalPage: number
    limit: number
  }
}
export interface GetDailyParam {
  date: Date,
}
export interface Daily {
  amount: number,
  productCoding: string,
  productsName: string,
}
export interface SuspendDeliveryParam {
  suspendCustomerId: number,
  dateArr: Date[],
  reason: string,
}
export interface Distribution {
  list: Customer[],
  milkman_id: number
}
export interface DistributionObj {
  [key: string]: Distribution
}
export interface MilkmanDistribution {
  [key: number]: DistributionObj
}
export interface pauseRecordingType {
  stopTime: string
  endStopTime: string
  suspendedDay: number
  reason: string
  optionTime: string
  optionUser: string
}

export interface changeMilkManParam {
  setCoustomerIdList: Array<number>
  milkmanId: number
}
export interface getStatementParam {
  dateArr?: Date[],
}

export function getCustomer (param: GetCustomerParam): Promise<Pagnate> {
  return ajax('/getCustomer', param, 'post')
}

export function addCustomer (param: CustomerOptionParam) {
  return ajax('/addCustomer', param, 'post')
}

export function todayDistribute (param: GetCustomerParam): Promise<Pagnate> {
  return ajax('/todayDistribute', param, 'post')
}

export function getDailyPlan (param: GetDailyParam): Promise<Daily[]> {
  return ajax('/getDailyPlan', param, 'post')
}

export function getStatement (param: getStatementParam): Promise<Daily[]> {
  return ajax('/getStatement', param, 'post')
}

export function suspendDelivery (param: SuspendDeliveryParam) {
  return ajax('/suspendDelivery', param, 'post')
}

export function setCustomerMessage (param: CustomerOptionParam) {
  return ajax('/setCustomerMessage', param, 'post')
}

export function getDistribution (): Promise<DistributionObj> {
  return ajax('/getDistribution', {}, 'post')
}

export function getMilkmanDistribution (): Promise<MilkmanDistribution> {
  return ajax('/getMilkmanDistribution', {}, 'post')
}

export function changeMilkMan (param: changeMilkManParam) {
  return ajax('/changeMilkMan', param, 'post')
}
